package com.qlylkj.lbk.ui.search

import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.style.CharacterStyle
import android.text.style.ForegroundColorSpan
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.forest.core.etx.getCompatColor
import com.qlylkj.lbk.R
import com.qlylkj.lbk.model.bean.Company

class SearchAdapter : BaseQuickAdapter<Company, BaseViewHolder>(R.layout.item_search) {

    private var keyword = ""

    fun setKeyword(keyword: String) {
        this.keyword = keyword
    }

    override fun convert(helper: BaseViewHolder, item: Company?) {
        helper.run {
            item?.run {
                val builder = SpannableStringBuilder(companyName)
                //昵称的颜色
                val keyWordColorSpan =
                    ForegroundColorSpan(mContext.getCompatColor(R.color.text_primary))
                builder.setSpan(
                    CharacterStyle.wrap(keyWordColorSpan),
                    0,
                    keyword.length,
                    Spannable.SPAN_EXCLUSIVE_INCLUSIVE
                )
                setText(R.id.companyNameText, builder)
            }
        }
    }
}